package com.xml;

import java.io.IOException;
import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import com.studay.bean.CheckResult;

public class PaseXml {
	public static CheckResult pase(InputStream in) {
		CheckResult result = new CheckResult();
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
		DocumentBuilder db;
		try {
			db = factory.newDocumentBuilder();
			Document doc = db.parse(in);
			Element element = doc.getDocumentElement();
			NodeList nodeList = element.getChildNodes();
			int i = 0;
			for (; i < nodeList.getLength(); i++) {
				Element chkElement = (Element) nodeList.item(i);
				String name = chkElement.getNodeName();
				if ("authFlag".equals(name)) {
					result.setAuthFlag(chkElement.getTextContent());
				} else if ("authMsg".equals(name)) {
					result.setAuthMsg(chkElement.getTextContent());
				} else if ("oraname".equals(name)) {
					result.setOraname(chkElement.getTextContent());
				} else if ("group".equals(name)) {
					result.setGroup(chkElement.getTextContent());
				}
			}
		} catch (ParserConfigurationException e) {
		} catch (SAXException e) {
		} catch (IOException e) {
		}
		return result;
	}
}